package com.jy.wms.common;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.User;
import com.joyi.gate.safety.vo.UserInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author niujiwei
 * @date 2017/12/12
 */
public class UserInfoUtils {

    public static UserInfo getUserInfo() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        User user = new User();
        UserInfo userInfo=  (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
        if(userInfo==null){
            System.out.println("session没了");
        }
        return userInfo;
    }

    public static User getUser() {
        UserInfo userInfo = getUserInfo();
        return userInfo!=null?userInfo.getUser():null;
    }

}
